package com.fengzan.hadoop;

import com.fengzan.hadoop.shellexcute.ShellExcute;
import com.fengzan.hadoop.socket.client.SocketClient;
import com.fengzan.hadoop.socket.server.SocketServer;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * hadoop安装
 */
public class HadoopStart {

    public static void main(String[] args) throws Exception {
//        System.out.println(socketServer.isHadooop1());
        File lockFile = new File("/usr/local/src/start_hadoop_lock.d");
        if (!lockFile.exists()){
            ShellExcute.excuteShell("expect -f /usr/local/src/sshKeygen.exp");
            lockFile=null;
        }else {
            System.out.println("--------------sshKeygen not need--------------");
        }
        Runnable serverRunnable= ()->{
            SocketServer socketServer = new SocketServer();
            socketServer.listen();
        };
        Thread serverTh = new Thread(serverRunnable);
        serverTh.start();
        Runnable clientRunnable=()->{
            List<String> hostList= new ArrayList<>();
            hostList.add("hadoop1");
            hostList.add("hadoop2");
            hostList.add("hadoop3");
            for (String host : hostList) {
                SocketClient socketClient = new SocketClient(host, 6655);
                System.out.println(host+"----链接");
            }
        };
        Thread clientTh = new Thread(clientRunnable);
        clientTh.start();
    }

}
